unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, DB, DBAccess, Uni, UniProvider, SQLServerUniProvider,
  DASQLMonitor, UniSQLMonitor, MemDS, ODBCUniProvider, AccessUniProvider,
  ADODB;

type
  TForm1 = class(TForm)
    Btnx_1: TButton;
    Btnx_2: TButton;
    UniConnection1: TUniConnection;
    SQLServerUniProvider1: TSQLServerUniProvider;
    Btnx_3: TButton;
    UniQuery1: TUniQuery;
    UniSQL1: TUniSQL;
    Btnx_4: TButton;
    Memo1: TMemo;
    AccessUniProvider1: TAccessUniProvider;
    con1: TADOConnection;
    ds1: TADODataSet;
    btn1: TButton;
    procedure Btnx_1Click(Sender: TObject);
    procedure Btnx_2Click(Sender: TObject);
    procedure Btnx_3Click(Sender: TObject);
    procedure Btnx_4Click(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

uses
  Class_Addx;

{$R *.dfm}

procedure TForm1.Btnx_1Click(Sender: TObject);
var
  addxa:TADDX;
begin
  UniConnection1.Connected;

  //
  addxa:=TADDX.Create;
  addxa.UNITLINK:='none';
  addxa.ADDXIDEX:=-1;
  addxa.CARDIDEX:=-1;
  addxa.ADDXSTRM:=TMemoryStream.Create;
  addxa.ADDXSTRM.LoadFromFile('1.jpg');
  addxa.ADDXNAME:='none';
  addxa.ADDXMEMO:='none';

  addxa.InsertDB(UniConnection1);
  //

  UniConnection1.Disconnect;
end;

procedure TForm1.Btnx_2Click(Sender: TObject);
var
  SQLA:string;
  addxa:TADDX;
begin
  UniConnection1.Connect;
  
  SQLA:='select top 1 * from tbl_addx';

  addxa:=TADDX(TADDX.ReadDB(SQLA,UniConnection1));
  if addxa<>nil then
  begin
    addxa.ADDXSTRM.SaveToFile('test.jpg');
  end;

  UniConnection1.Disconnect;
end;

procedure TForm1.Btnx_3Click(Sender: TObject);
var
  I:Integer;
  TempA:string;
  TempB:string;
  SQLA:string;
  STRMA:TMemoryStream;
begin
  SQLA:='select addx_idex from tbl_addx';
  UniQuery1.SQL.Text:=sqla;
  UniQuery1.Open;

  ShowMessageFmt('%D',[UniQuery1.RecordCount]);

  
  for i:=0 to UniQuery1.Fields.Count-1 do
  begin
    TempA:=TempA+','+UniQuery1.Fields.Fields[I].FieldName;
    TempB:=TempB+',:'+UniQuery1.Fields.Fields[I].FieldName;
  end;
  Delete(TempA,1,1);
  Delete(TempB,1,1);
  SQLA:=Format('insert into tbl_addx_demo (%S) values (%S)',[TempA,TempB]);
  ShowMessage(SQLA);

  UniSQL1.SQL.Text:=SQLA;
  
  UniQuery1.First;
  while not UniQuery1.Eof do
  begin

    //for I:=0 to UniQuery1.FieldDefs.Count-1 do
    for I:=0 to UniQuery1.Fields.Count-1 do 
    begin
      if UniQuery1.FieldDefs.Items[I].DataType=ftBlob then
      begin
        STRMA:=TMemoryStream.Create;
        TBlobField(UniQuery1.FieldByName(UniQuery1.FieldDefs.Items[I].Name)).SaveToStream(STRMA);
        UniSQL1.ParamByName(UniQuery1.FieldDefs.Items[I].Name).LoadFromStream(STRMA,ftBlob);
        FreeAndNil(STRMA);
      end else
      begin
        UniSQL1.ParamByName(UniQuery1.FieldDefs.Items[I].Name).Value:=UniQuery1.Fields[I].Value;
      end;  

    end;
    UniSQL1.Execute;

    UniQuery1.Next;
  end;  
end;

procedure TForm1.Btnx_4Click(Sender: TObject);
var
  SQLA:string;
  UniQuery:TUniQuery;
  StrA:string;
begin
  UniConnection1.Connect;
  
  SQLA:='select * from tbl_gzgs where gzjg_id=3';
  UniQuery1:=TADDX.GetUniQuery(SQLA,UniConnection1);

  
  StrA:=UniQuery1.FieldByName('FORMAT_NR').AsString;
  Memo1.Lines.Clear;
  Memo1.Lines.Add(StrA);
  
  
  UniConnection1.Disconnect;
end;

procedure TForm1.btn1Click(Sender: TObject);
var
  I:Integer;
begin
  //
  con1.Connected:=True;
  self.ds1.Connection:=con1;

  ds1.CommandText:='select * from tbl_gzjg';
  ds1.Open;

  Memo1.Lines.Clear;
  for I:=0  to ds1.FieldDefs.Count-1 do
  begin
    //ds1.FieldDefs.Items[I].

  end;

  for I:=0 to ds1.IndexDefs.Count-1 do
  begin
    Memo1.Lines.Add(ds1.IndexDefs.Items[I].Name);
  end;  

end;

end.
